import axios from 'axios'
import { promises } from 'fs';

const service = axios.create({ timeout:10000})

service.interceptors.request.use( config => {
  if( config.url.indexOf('hospitalInfo/hms/getAreaList') == -1) {
      //无token
    if (!sessionStorage.getItem('hospitalAuth')) {
      window.back.$router.push('/')
    }
  }
  if ( config.url !== 'super_yaji/hospitalAuth/hms/login') {
    config.headers.hospitalAuth = sessionStorage.getItem('hospitalAuth')
  }
  return config
}, error => {
  return Promise.reject(error)
})
service.interceptors.response.use( response => {
  if(response.data.code == -1003){
    window.back.$router.push('/')
  }
  return response
}, error => {
  return Promise.reject(error)
}) 
export default service